package com.sz.netty.service.impl;

import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.sz.netty.entity.DtuFtpCardInfo;
import com.sz.netty.mapper.NettyDtuFtpCardInfoMapper;
import com.sz.netty.service.DtuFtpCardInfoService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * DTU FTP卡信息服务实现类
 */
@Service
public class NettyDtuFtpCardInfoServiceImpl extends ServiceImpl<NettyDtuFtpCardInfoMapper, DtuFtpCardInfo> implements DtuFtpCardInfoService {
    
    @Override
    public DtuFtpCardInfo saveCardInfo(DtuFtpCardInfo cardInfo) {
        // 设置创建时间和更新时间
        Date now = new Date();
        if (cardInfo.getCreateTime() == null) {
            cardInfo.setCreateTime(now);
        }
        cardInfo.setUpdateTime(now);
        
        // 设置删除标志默认值
        if (cardInfo.getDelFlag() == null) {
            cardInfo.setDelFlag("F");
        }
        
        // 保存到数据库
        this.save(cardInfo);
        return cardInfo;
    }
    
    @Override
    public DtuFtpCardInfo findByCardInfo(String cardInfo) {
        // 创建查询条件
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.where("card_info = ?", cardInfo);
        
        // 查询数据库
        return this.getOne(queryWrapper);
    }
}